﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using SimulationCore.Net.DTO;
using SimulationPresenter.Presentation.Helpers;
using SimulationPresenter.Presentation.Primitives;
using SimulationPresenter.Simulation.Helpers;
using SimulationPresenter.Simulation.Primitive;
using SimulationPresenter.Theater.Enums;
using PresentationBox = SimulationPresenter.Presentation.Primitives.BoxShape;
using InvalidDataException = System.IO.InvalidDataException;
using Enviroment = SimulationPresenter.Simulation.SimulationEnvironment;

namespace SimulationPresenter.Theater.Actors
{
    internal class BoxActor : RidigActorPrimitive, IDrawable, ISimulatable, ITypeDiscoverableActor, IActorPropertiesProvider, IRidigActorPropertiesProvider
    {
        private IPresentationPrimitive shape;
        internal BoxActor(IPresentationPrimitive presentationBox,
                        IRidig simulationBody)
        {
            shape = presentationBox;
            state = simulationBody;
        }

        /// <summary>
        /// Draws an Actor to given Device
        /// </summary>
        /// <param name="device"></param>
        public void DrawActor(Device device)
        {
            IndexedVerticesDrawer.Draw(shape, state.Transformation, device);
        }

        public void Highlight(Color colorValue)
        {
            shape.Color = colorValue;
        }

        #region ITypeDiscoverableActor
        public ActorType ActorType
        {
            get { return ActorType.Ridig; }
        }
        #endregion

        #region IRidigActorPropertiesProvider
        public bool Visible
        {
            get { return shape.Visible; }
            set { shape.Visible = value; }
        }

        public float Density
        {
            get
            {
                try
                {
                    return (state as RidigBox).Density;
                }
                catch (NullReferenceException)
                {
                    throw new InvalidDataException("State is not a ridig, so Actor does not define Density.");
                }
            }
            set
            {
                try
                {
                    (state as RidigBox).Density = value;
                }
                catch (NullReferenceException)
                {
                    throw new InvalidDataException("State is not a ridig, so Actor does not define Density.");
                }
            }
        }
        #endregion
    }
}
